package hu.ibm.dao;

import hu.ibm.model.User;

import java.util.List;

import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Service;

@Service
public class UserDAO extends GenericDAO<User> {

	@Override
	Class<User> getEntityClass() {
		return User.class;
	}

	@Override
	long getId(User entity) {
		return entity.getId();
	}

	public List<User> getUsers() {
		return entityManager.createQuery("SELECT o FROM User o", User.class)
				.getResultList();
	}

	public User getUserByName(String name) {
		Query query = entityManager
				.createQuery("SELECT o FROM User o where o.userName=:name");
		query.setParameter("name", name);
		return (User) query.getSingleResult();

	}
}
